define(function (require, exports, module) {
	var CMISService = require("./CMISService");   
    var FolderTree = require("./component/FolderTree");
    var PendingFilingTable = require("./component/PendingFilingTable");
	$(function() {
		CMISService.getFolderTree().done(function(data) {
			ReactDOM.render(React.createElement(FolderTree, {
				data: data,
				option: {
					id: 'folderNav',
					style: 'tree-solid-line'
				}
			}), $("#document-navigation .tree-box")[0]);
		});


		showDocument(pendingFilingDocument);

		function showDocument(searchResult) {
			ReactDOM.render(React.createElement(PendingFilingTable, {
				data: searchResult.data
			}), $("#unfilingDocument")[0]);
		}

		$("#filingDocument").on("click", function() {
			var selectedDocument = $("#unfilingDocument>:first-child").data("getSelectedDocument")();
			if (selectedDocument.length === 0){
				UCX_Utils.alert('Alert', "请选择要归档的文件！");
				return;
			}

			var ret = _.every(selectedDocument, function(document){				
				if (!document.path || document.path.length === 0){
					UCX_Utils.alert('Alert', document.name + "</br>请选择归档位置！");
					return false;
				}		
				return true;	
			});		
			if (!ret) return;
			CMISService.filingDocument(selectedDocument).always(function(response){
				window.pendingFilingDocument = response.data;
				showDocument(pendingFilingDocument);
			})
			.fail(function(response){
				UCX_Utils.alert('Error', response.message);
			});
		});
	});
});